package 线程.day3.demo4;

import java.util.concurrent.locks.ReentrantLock;

public class Sell implements Runnable{
    static int num=1000;
    static ReentrantLock lc=new ReentrantLock(true);

    @Override
    public void run() {
        while (num>0){
            try{
                lc.lock();
                //lc.tryLock(10, TimeUnit.SECONDS);
                if(num<=0){
                    return;
                }
                System.out.println(Thread.currentThread().getName()+"卖出票："+num);
                num--;
                //int i=1/0;

            }catch (Exception e){
            }
            finally {
                lc.unlock();
            }

            //Thread.yield();

        }
    }

}
